﻿using DoNet.Common.App;
using System.Security.Claims;

namespace DoNet.Common.Services
{
    public class CurrentUserService : ICurrentUserService
    {
        private readonly ClaimsPrincipal? claimsPrincipal;

        public CurrentUserService()
        {
            claimsPrincipal = HttpContextLocal.Current()?.User;
        }

        public string UserId => claimsPrincipal?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty;

        public string UserName => claimsPrincipal?.Identity?.Name ?? string.Empty;

        public bool IsAuthenticated => claimsPrincipal?.Identity?.IsAuthenticated ?? false;
    }
}
